using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.SupplyChain.Warehouse;
using HengTong.Model.Db.SupplyChain.Material;
using HengTong.Model.Db.SupplyChain.Partner;
using HengTong.Model;


namespace HengTong.ViewModel.SupplyChain.SysWarehouseStockVms
{
    public partial class SysWarehouseStockListVm : BaseListVm<SysWarehouseStockView, SysWarehouseStockSearcher>
    {

        protected override IEnumerable<IGridColumn<SysWarehouseStockView>> InitGridHeader()
        {
            return new List<GridColumn<SysWarehouseStockView>>{
                this.MakeGridHeader(x => x.LocationName),
                this.MakeGridHeader(x => x.MaterialName),
                this.MakeGridHeader(x => x.Quantity),
                this.MakeGridHeader(x => x.SkuName),
                this.MakeGridHeader(x => x.ErpId),
                this.MakeGridHeader(x => x.BatchNumber),
                this.MakeGridHeader(x => x.PartnerName),
                this.MakeGridHeader(x => x.StoreType),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysWarehouseStockView> GetSearchQuery()
        {
            var query = DC.Set<SysWarehouseStock>()
                .CheckEqual(Searcher.LocationId, x=>x.LocationId)
                .CheckEqual(Searcher.MaterialId, x=>x.MaterialId)
                .CheckEqual(Searcher.SkuId, x=>x.SkuId)
                .CheckContain(Searcher.ErpId, x=>x.ErpId)
                .CheckContain(Searcher.BatchNumber, x=>x.BatchNumber)
                .CheckEqual(Searcher.PartnerId, x=>x.PartnerId)
                .CheckEqual(Searcher.StoreType, x=>x.StoreType)
                .Select(x => new SysWarehouseStockView
                {
				    ID = x.ID,
                    LocationName = x.Location.Name,
                    MaterialName = x.Material.Name,
                    Quantity = x.Quantity,
                    SkuName = x.Sku.Name,
                    ErpId = x.ErpId,
                    BatchNumber = x.BatchNumber,
                    PartnerName = x.Partner.Name,
                    StoreType = x.StoreType,
                })
                .OrderBy(x => x.ID);
            return query;
        }
    }
}
